<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>

</head>

<body>

    <input type="text" id="max" value="99" />
    <input type="text" id="min" value="0" />
    <input type="text" id="num" value="55" />
    <input type="button" id="btn" value="生成" />
    <input type="button" id="btn1" value="排序" />
    <input type="button" id="btn2" value="去重" />
</body>
<script>
    var oMax = document.getElementById("max")
    var oMin = document.getElementById("min")
    var oNum = document.getElementById("num")
    var oBtn = document.getElementById("btn")
    var oBtn1 = document.getElementById("btn1")
    var oBtn2 = document.getElementById("btn2")
    var arr = [];
    oBtn.onclick = function () {
        console.log(oNum.value)
        for (var d = 0; d < oNum.value; d++) {
            arr[d] = random(oMax.value, oMin.value)
            oNum.value = arr[d]
        }
        //范围随机函数的封装
        function random(max, min) {
            return Math.round(Math.random() * (max - min) + min)
        }
        console.log(arr)
    }
    //排序
    //数组的排序最重要的一点就是遍历，此处数组的冒泡排序
    oBtn1.onclick = function () {
        for (var i = 0; i < arr.length - 1; i++) {
            for (var j = 0; j < arr.length - i - 1; j++) {
                var sum;
                if (arr[j] > arr[j + 1]) {
                    sum = arr[j + 1];
                    arr[j + 1] = arr[j];
                    arr[j] = sum;
                }
            }
        }
        console.log(arr)
    }

    // 去重
    oBtn2.onclick = function () {
        for (var a = 0; a < arr.length; a++) {
            for (var e = a + 1; e < arr.length; e++) {
                if (arr[a] == arr[e]) {
                    arr.splice(e, 1);
                    e--;
                }
            }
        }
        console.log(arr);
    }
</script>

</html>